import { createRouter, createWebHistory } from 'vue-router'
import { ElMessageBox } from 'element-plus';
import { useBaseStore } from '@/stores/baseStore';

const routes = [
	{
		path: '',
		redirect: '/home'
	},
	{
		path: '/',
		redirect: '/home'
	},
	{
		path: '/home',
		name: 'home',
		component: () => import('@/view/page/HomeVue.vue'),
	},
	{
		path: '/cartoon',
		name: 'cartoon',
		component: () => import('@/view/page/CartoonVue.vue'),
	},
	{
		path: '/cartoonDetail/:cid',
		name: 'cartoonDetail',
		component: () => import('@/view/page/CartoonDetail.vue'),
	},
	{
		path: '/novel',
		name: 'novel',
		component: () => import('@/view/page/NovelVue.vue'),
	},
	{
		path: '/novelDetail/:nid',
		name: 'novelDetail',
		component: () => import('@/view/page/NovelDetail.vue'),
	},
	{
		path: '/search',
		name: 'search',
		component: () => import('@/view/page/SearchVue.vue'),
	},
	{
		path: '/setting',
		name: 'setting',
		component: () => import('@/view/page/SettingVue.vue'),
	},
	{
		path: '/tool',
		name: 'tool',
		component: () => import('@/view/page/ToolVue.vue'),
	},
	{
		path: '/download/:listUrl',
		name: 'download',
		component: () => import('@/view/page/DownloadVue.vue'),
	},
	{
		// 独立组件
		path: '/cartoonWatcher/:cid/:chapterName',
		name: 'cartoonWatcher',
		meta: {
			showContent: 'cartoonWatcher'
		}
	},
	{
		path: '/novelWatcher/:nid/:chapterName',
		name: 'novelWatcher',
		meta: {
			showContent: 'novelWatcher'
		}
	},
]

const router = createRouter({
	mode: 'hash',
	history: createWebHistory(),
	routes
})

router.beforeEach((to, from) => {
	return true;
})

router.afterEach((to, from) => {
	// console.log("from: " + from.path);
	// console.log("to: " + to.path);
	// console.log("currentRoute.path: " + router.currentRoute._value.path); 
	// console.log(router); 

	const baseStore = useBaseStore();

	if (to.meta.showContent) {
		baseStore.setContent(to.meta.showContent)
	}
})

export default router
